package mns.modules.output.email;

import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;

import mns.*;

/**
 * 
 * @author Dan Moore
 *
 */
public class EmailModule implements MNSOutputModule {

	public boolean sendMessage(MNSMessage msg, UserOptions opts) {
		UserOption opt = null;
		String email = null;
		if((opt = opts.getOption("email")) != null) {
			email = opt.getValue();
		} else {
			System.err.println("Bad User Options, not sending message.");
			return false;
		}
		
		try {
			EMail.sendMail(email, "msg@mns.com", "", msg.getLongMessage());
		} catch (NoSuchProviderException e) {
			System.err.println(e.toString() + "in EmailModule.sendMessage().");
			return false;
		} catch (MessagingException e) {
			System.err.println(e.toString() + "in EmailModule.sendMessage().");
			return false;
		}
		return true;
	}

	public String getName() {
		return "Generic E-mail Output Module";
	}

	public String getOptionsFormHTML() {
		return "Email Address: <input type=\"text\" name=\"email\" value=\"example@domain.com\" />";
	}

	public String getDescriptionHTML() {
		// TODO Auto-generated method stub
		return "";
	}

}
